﻿namespace HZY.Framework.Core.CustomExceptionHandling;

/// <summary>
/// Warning message
/// </summary>
public class MessageBoxException : Exception
{
    private readonly R _apiResult;

    private MessageBoxException(R apiResult) : base(apiResult.ErrorMessage)
    {
        this._apiResult = apiResult;
    }

    /// <summary>
    /// Acquire ApiResult
    /// </summary>
    /// <returns></returns>
    public R GetResult() => _apiResult;

    /// <summary>
    /// Create error message and data
    /// </summary>
    /// <param name="httpStatusCode"> StatusCodes.Status200OK </param>
    /// <param name="message">Message content</param>
    /// <param name="data"></param>
    /// <returns></returns>
    public static MessageBoxException Create(HttpStatusCode httpStatusCode, string message, object data)
    {
        return new MessageBoxException(ApiResult.Result(httpStatusCode, message, data));
    }

    /// <summary>
    /// Create error message
    /// </summary>
    /// <param name="message">Message content</param>
    /// <returns></returns>
    public static MessageBoxException CreateOkMessage(string message)
    {
        return new MessageBoxException(ApiResult.ResultMessage(HttpStatusCode.OK, message));
    }

    /// <summary>
    /// Create error data
    /// </summary>
    /// <param name="data">Message content</param>
    /// <returns></returns>
    public static MessageBoxException CreateOkData(object data)
    {
        return new MessageBoxException(ApiResult.ResultData(HttpStatusCode.OK, data));
    }

    /// <summary>
    /// Create error message
    /// </summary>
    /// <param name="httpStatusCode"> StatusCodes.Status200OK </param>
    /// <param name="message">Message content</param>
    /// <returns></returns>
    public static MessageBoxException CreateMessage(HttpStatusCode httpStatusCode, string message)
    {
        return new MessageBoxException(ApiResult.ResultMessage(httpStatusCode, message));
    }

    /// <summary>
    /// Create error data
    /// </summary>
    /// <param name="httpStatusCode"> StatusCodes.Status200OK </param>
    /// <param name="data">Message content</param>
    /// <returns></returns>
    public static MessageBoxException CreateData(HttpStatusCode httpStatusCode, object data)
    {
        return new MessageBoxException(ApiResult.ResultData(httpStatusCode, data));
    }
}